<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
                   
class Hessian extends CI_Controller {

	function __construct() {
		parent::__construct();		$this->load->library('Maitaidata');
	}	 
           
	public function index(){	
	}

	public function getgadgetlist(){

		$arr =  get_object_vars($this->maitaidata->getGadgetList("","",10,10000)) ;
		var_dump($arr);
	}
 	
	public function getpromotypelist(){
		$arr = json_encode(get_object_vars($this->maitaidata->getPromoTypeList(""))) ;
		die($arr);
	}
 
	public function getstorelist(){
		$arr =  get_object_vars($this->maitaidata->getStoreList("","","")) ;
		var_dump($arr);
	}
	public function getpromovaliditylist(){
		$arr =  json_encode(get_object_vars($this->maitaidata->getPromoValidityList("8"))) ;
		die($arr);
	}
	public function getpromolist(){ // not working params
		//$arr =  get_object_vars($this->maitaidata->getPromoList("9","UNLI CALLS",64)) ;
		$arr =  get_object_vars($this->maitaidata->getPromoList("13","UNLI CALLS",7)) ;
		var_dump($arr);
	}
	public function getcommitmentperiod(){
		//$arr =  get_object_vars($this->maitaidata->getCommitmentPeriod("15")) ;
		$arr =  get_object_vars($this->maitaidata->getCommitmentPeriod("15", 9200)) ;
		var_dump($arr);
	}
	public function checkmsisdn($num){
		// not working
		$arr =  get_object_vars($this->maitaidata->checkMsisdn($num)) ;
		var_dump($arr);
	}
	public function registersubscriber(){
		// param should be object 

		$fName = "firstq";
		$mName = "middleq";
		$lName = "last";
		$email = "test@fluxion.com.ph";
		$msisdn = "09151001017";
		$birthdate = "10/10/2014";
		$streetNum = "addresssQQ";
		$area = "";
		$town = "Balite";
		$province = "Batangas";
		$postalCode = "4219";
		$gadgetId = "27";
		$promoId = "1";
		$commitmentPeriod = "12";
		$storeId = "25";
		$channelId = "2";		
		$nName = "test nick";

		$arr =  get_object_vars($this->maitaidata->registerSubscriber($fName, $mName, $lName, $email, $msisdn, $birthdate, $streetNum, $area, $town, $province, $postalCode, $gadgetId, $promoId, $commitmentPeriod, $storeId, $channelId, $nName)) ;
		var_dump($arr);
	}

	public function getsubscriptiondetails($promocode){
		$arr =  get_object_vars($this->maitaidata->getsubscriptiondetails($promocode)) ;
		var_dump($arr);
	}

	public function keyexist($sku)
	{
		$this->config->load('config_maitai_shopapi');
		$ch = curl_init($this->config->item('maitai_shopapi_url') . $sku);    // initialize curl handle
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$product_array = curl_exec($ch);  
		$product = json_decode($product_array);
		
		$produkto = $product[0];
		if(array_key_exists("imageurl", $produkto)) echo "imageurl exists<br /><img src='" . $produkto->imageurl . "' />";
			else echo "imageurl DOES NOT exists<br />";
		if(array_key_exists("imageurl_2", $produkto)) echo "imageurl_2 exists<br /><img src='" . $produkto->imageurl_2 . "' />";
			else echo "imageurl_2 DOES NOT exists<br />";

		for($ctr = 1; $ctr < 10; $ctr++) {
			$array_key = ($ctr!=1) ? "imageurl_" . $ctr : "imageurl";
			if(array_key_exists($array_key, $produkto)):
				echo $array_key . " exists <img src='" . $produkto->$array_key . "' /><br />";
			else:
				echo $array_key . " DOES NOT exists<br />";
			endif;
		}
		die();
	}
	
}
